import demo1.ListNode;

class Solution2 {
    public ListNode middleNode(ListNode head) {
       if(head == null) {
          return null;
       }
       if(head.next == null) {
          return head;
       }
       ListNode fast = head;
       ListNode slow = head;
       while(fast != null && fast.next != null) {
          fast = fast.next.next;
          slow = slow.next;
       }
       return slow;
    }
}